package github.kawaiior.yuanchuxiuzhen.common.entity.addon.model;

import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import github.kawaiior.yuanchuxiuzhen.common.entity.addon.BeastKingEntity;
import github.kawaiior.yuanchuxiuzhen.util.RenderUtil;
import net.minecraft.client.renderer.entity.model.EntityModel;
import net.minecraft.client.renderer.model.ModelRenderer;
import net.minecraft.util.math.MathHelper;

public class BeastKingEntityModel extends EntityModel<BeastKingEntity> {
    private final ModelRenderer body;
    
    private final ModelRenderer wei;
    
    private final ModelRenderer rightleg;
    
    private final ModelRenderer rightleg2;
    
    private final ModelRenderer leftleg;
    
    private final ModelRenderer leftleg2;
    
    private final ModelRenderer rightarm;
    
    private final ModelRenderer rightarm2;
    
    private final ModelRenderer leftarm;
    
    private final ModelRenderer leftarm2;
    
    private final ModelRenderer head;
    
    private final ModelRenderer bone;
    
    private final ModelRenderer bone2;
    
    private final ModelRenderer bone3;

    public BeastKingEntityModel(){
        this.textureWidth=128;
        this.textureHeight=132;
        this.body=new ModelRenderer(this);
        this.body.setRotationPoint(0.0F,24.0F,0.0F);
        addBox(this.body, 0, 0, -8.0F, -36.0F, -13.0F, 16, 16, 16, 0.0F, false);
        addBox(this.body, 0, 84, -9.0F, -37.0F, -14.0F, 18, 18, 18, 0.0F, false);
        addBox(this.body, 0, 32, -7.0F, -34.0F, 3.0F, 14, 14, 10, 0.0F, false);
        addBox(this.body, 64, 0, -7.0F, -36.0F, 13.0F, 14, 16, 16, 0.0F, false);
        this.wei=new ModelRenderer(this);
        this.wei.setRotationPoint(0.0F,-34.0F,29.0F);
        RenderUtil.setRotationAngle(this.wei,0.3491F,0.0F,0.0F);
        this.body.addChild(this.wei);
        addBox(this.wei, 36, 56, -1.0F, 0.0F, -1.0F, 2, 16, 2, 0.0F, false);
        addBox(this.wei, 44, 56, -1.5F, 16.0F, -1.5F, 3, 8, 3, 0.0F, false);
        this.rightleg=new ModelRenderer(this);
        this.rightleg.setRotationPoint(-7.0F,-5.0F,20.0F);
        addBox(this.rightleg, 0, 56, -5.0F, -2.0F, -6.0F, 6, 16, 12, 0.0F, false);
        this.rightleg2=new ModelRenderer(this);
        this.rightleg2.setRotationPoint(0.0F,14.0F,1.0F);
        this.rightleg.addChild(this.rightleg2);
        addBox(this.rightleg2, 100, 43, -4.0F, 0.0F, 0.0F, 4, 12, 7, 0.0F, false);
        addBox(this.rightleg2, 100, 32, -5.0F, 12.0F, -3.0F, 6, 3, 8, 0.0F, false);
        this.leftleg=new ModelRenderer(this);
        this.leftleg.setRotationPoint(7.0F,-5.0F,20.0F);
        addBox(this.leftleg, 0, 56, -1.0F, -2.0F, -6.0F, 6, 16, 12, 0.0F, false);
        this.leftleg2=new ModelRenderer(this);
        this.leftleg2.setRotationPoint(0.0F,14.0F,1.0F);
        this.leftleg.addChild(this.leftleg2);
        addBox(this.leftleg2, 100, 43, 0.0F, 0.0F, 0.0F, 4, 12, 7, 0.0F, false);
        addBox(this.leftleg2, 100, 32, -1.0F, 12.0F, -3.0F, 6, 3, 8, 0.0F, false);
        this.rightarm=new ModelRenderer(this);
        this.rightarm.setRotationPoint(-9.0F,-3.0F,-4.5F);
        addBox(this.rightarm, 48, 32, -4.0F, -2.0F, -5.5F, 6, 14, 10, 0.0F, false);
        this.rightarm2=new ModelRenderer(this);
        this.rightarm2.setRotationPoint(-1.0F,12.0F,4.5F);
        this.rightarm.addChild(this.rightarm2);
        addBox(this.rightarm2, 80, 32, -2.0F, 0.0F, -6.0F, 4, 12, 6, 0.0F, false);
        addBox(this.rightarm2, 100, 32, -3.0F, 12.0F, -9.0F, 6, 3, 8, 0.0F, false);
        this.leftarm=new ModelRenderer(this);
        this.leftarm.setRotationPoint(9.0F,-3.0F,-4.5F);
        addBox(this.leftarm, 48, 32, -2.0F, -2.0F, -5.5F, 6, 14, 10, 0.0F, false);
        this.leftarm2=new ModelRenderer(this);
        this.leftarm2.setRotationPoint(1.0F,12.0F,4.5F);
        this.leftarm.addChild(this.leftarm2);
        addBox(this.leftarm2, 80, 32, -2.0F, 0.0F, -6.0F, 4, 12, 6, 0.0F, false);
        addBox(this.leftarm2, 100, 32, -3.0F, 12.0F, -9.0F, 6, 3, 8, 0.0F, false);
        this.head=new ModelRenderer(this);
        this.head.setRotationPoint(0.0F,-11.0F,-14.0F);
        addBox(this.head, 56, 56, -6.0F, -5.0F, -9.0F, 12, 12, 10, 0.0F, false);
        addBox(this.head, 56, 78, -5.0F, 0.0F, -14.0F, 10, 8, 6, 0.0F, false);
        addBox(this.head, 72, 92, -3.0F, -14.0F, -4.0F, 6, 12, 14, 0.0F, false);
        this.bone=new ModelRenderer(this);
        this.bone.setRotationPoint(0.0F,-5.0F,-4.0F);
        RenderUtil.setRotationAngle(this.bone,0.5236F,0.0F,0.0F);
        this.head.addChild(this.bone);
        addBox(this.bone, 0, 120, -6.0F, 0.0F, 0.0F, 12, 0, 12, 0.0F, false);
        this.bone2=new ModelRenderer(this);
        this.bone2.setRotationPoint(6.0F,-5.0F,-3.0F);
        RenderUtil.setRotationAngle(this.bone2,0.6109F,0.0F,1.5708F);
        this.head.addChild(this.bone2);
        addBox(this.bone2, 0, 120, -2.0F, 0.0F, 0.0F, 12, 0, 12, 0.0F, false);
        this.bone3=new ModelRenderer(this);
        this.bone3.setRotationPoint(-6.0F,-5.0F,-3.0F);
        RenderUtil.setRotationAngle(this.bone3,-0.6109F,0.0F,1.5708F);
        this.head.addChild(this.bone3);
        addBox(this.bone3, 0, 120, -2.0F, 0.0F, 0.0F, 12, 0, 12, 0.0F, false);
        
        
    }

    private void addBox(ModelRenderer mb, int tx, int ty, float x, float y, float z, float width, float height, float depth, float delta, boolean mirrorIn){
        ModelRenderer mr = new ModelRenderer(this);
        mb.addChild(mr);
        mr.setTextureOffset(tx, ty).addBox(x,y,z,width,height,depth,delta,mirrorIn);
    }

    @Override
    public void setRotationAngles(BeastKingEntity entityIn, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) {
        this.rightleg2.rotateAngleX = MathHelper.cos(limbSwing * 1.0F) * 1.0F * limbSwingAmount;
        this.rightarm.rotateAngleX = MathHelper.cos(limbSwing * 1.0F) * -1.0F * limbSwingAmount;
        this.leftleg.rotateAngleX = MathHelper.cos(limbSwing * 1.0F) * -1.0F * limbSwingAmount;
        this.rightarm2.rotateAngleX = MathHelper.cos(limbSwing * 1.0F) * 1.0F * limbSwingAmount;
        this.leftarm2.rotateAngleX = MathHelper.cos(limbSwing * 1.0F) * -1.0F * limbSwingAmount;
        this.head.rotateAngleY = netHeadYaw / 57.295776F;
        this.head.rotateAngleX = headPitch / 57.295776F;
        this.rightleg.rotateAngleX = MathHelper.cos(limbSwing * 1.0F) * 1.0F * limbSwingAmount;
        this.leftarm.rotateAngleX = MathHelper.cos(limbSwing * 1.0F) * 1.0F * limbSwingAmount;
        this.leftleg2.rotateAngleX = MathHelper.cos(limbSwing * 1.0F) * -1.0F * limbSwingAmount;
    }

    @Override
    public void render(MatrixStack matrixStackIn, IVertexBuilder bufferIn, int packedLightIn, int packedOverlayIn, float red, float green, float blue, float alpha) {
        
        this.body.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
        this.rightleg.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
        this.leftleg.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
        this.rightarm.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
        this.leftarm.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
        this.head.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
        

    }
}